<script src="components/com_questionare/public/uploadlib/jquery.min.js" type="text/javascript"></script>
<script src="components/com_questionare/public/uploadlib/jquery.uploadify.min.js" type="text/javascript"></script>
<link rel="stylesheet" type="text/css" href="components/com_frmessage/public/uploadlib/uploadify.css"/>

<script type="text/javascript" src="../media/system/js/jQuery.vietvang.validate.js"></script>
	<script type="text/javascript">
		$(document).ready(function(){
			$('#adminForm').validate({
			});
		});
</script>


<form action="index.php?option=com_questionare" method="post" class="adminform" id="adminForm" name="adminForm" enctype="multipart/form-data">
    <table class="tbl-ques" border=0>
    	<tr>
            <td style="width: 30%;font-size: 1.091em;" class="right">ID</td>
    		<td style="width: 40%;vertical-align:top;font-size: 1.091em">
                <label style="line-height: 13px;"><?php echo HelperBG::getIDAuto('serq','SERQ_CODE');?></label>
                <input name="jform[SERQ_CODE]" type="hidden"  value="<?php echo HelperBG::getIDAuto('serq','SERQ_CODE'); ?>" />
            </td>
    		<td style="width: 40%;"><span style="color: red;font-size: small;font-family: 'ＭＳ Ｐゴシック', Osaka;text-align: left;">※印は入力必須項目です。</span></td>
    	</tr>
    	<tr>
    		<td><label class="right">アンケート名<span style="color: red;font-size: small;font-family: 'ＭＳ Ｐゴシック', Osaka;">※</span></label>	</td>
    		<td colspan="2"><input type="text" name="jform[SERQ_TITLE]" class="inputbox width" size="30" value="<?php echo $this->row->SERQ_TITLE; ?>"/></td>
    	</tr>
    	<tr>
    		<td>
                <label class="right">説明</label>	
            </td>
    		<td colspan="2"> <textarea cols="44" rows="6" name="jform[SERQ_DESCRIPTION]" style="width: 395px;"><?php echo $this->row->SERQ_DESCRIPTION; ?></textarea></td>
    	</tr>
        <tr>
        
            <td ><label class="right">画像</label></td>
            <td>
                <input type="file" id="jformSERQ_IMG" name="jformSERQ_IMG" class="big" size="30" />
                <span style="font-size: 1.091em;color: blue;">(推奨される画像の縦横比は「1:1」です。)</span>
                <input type="hidden" name="jform[SERQ_IMG_NEW]" id="value_SERQ_IMG" value="" />
                
            </td>
            <td id="preview"> <img class="img_questionare" style="width: 100px; height: 100px;" id="showimg"  /></td>
        
        </tr>
        <tr>
            <td><label class="right">配信先<span style="color: red;font-size: small;font-family: 'ＭＳ Ｐゴシック', Osaka;">※</span></label></td>
            <td colspan="2">
                <input id="btnSERQ_SEND_USER_ID_LIST" name="btnSERQ_SEND_USER_ID_LIST"  type="button" value="配信先追加"/>
                
            </td>
        </tr>
        <tr>
            <td></td>
            <td colspan="2"><textarea id="jformMAIL_USER" name="jform[SERQ_SEND_USER_ID_LIST]" cols="44" rows="6" style="width: 395px;"><?php echo $this->row->SERQ_SEND_USER_ID_LIST; ?></textarea></td>
        </tr>
    
        <tr>
            <td><label class="right">エンドページタイトル</label></td>
            <td colspan="2">
                <input type="text" name="jform[SERQ_END_TITLE]" class="inputbox width" size="30" />
            </td>
        </tr>
        <tr>
            <td><label class="right">エンドページ説明</label></td>
            <td colspan="2">
                 <textarea cols="44" rows="4" name="jform[SERQ_END_DESCRIPTION]" style="width: 395px;"><?php echo $this->row->SERQ_END_DESCRIPTION; ?></textarea>
            </td>
        </tr>
        <tr>
            <td style="width:25%;"><label class="right">開始日<span style="color: red;font-size: small;font-family: 'ＭＳ Ｐゴシック', Osaka;">※</span></label></td>
            <td>
                <?php echo JHtml::calendar('', 'jform[SERQ_START]', 'jformSERQ_START');?>
                <span name="msg_error"></span> 
            </td>
            <td>
                
            </td>
            
        </tr>
        <tr>
            <td><label class="right">終了日<span style="color: red;font-size: small;font-family: 'ＭＳ Ｐゴシック', Osaka;">※</span></label></td>
            <td colspan="2">
                <?php echo JHtml::calendar('', 'jform[SERQ_FINISH]', 'jformSERQ_FINISH');?>
                <span name="msg_error"></span> 
            </td>
        </tr>
         <tr>
            <td><label class="right">フロントページ<span style="color: red;font-size: small;font-family: 'ＭＳ Ｐゴシック', Osaka;">※</span></label></td>
            <td colspan="2">
                <select id="jform[SERQ_PUBLISHED]" name="jform[SERQ_PUBLISHED]" class="width" >
                    <option value="-1" selected="">選択してください</option>
                    <option value="1" >公開</option>
                    <option value="0">非公開 </option>
                </select>
            </td>
        </tr>
    </table>
  <div>
		<input type="hidden" name="task" value="" />
		<input type="hidden" name="boxchecked" value="0" />
		
  </div>
</form>

<?php $timestamp = time();?>
<script>

    
  
    $(function() {
        $('#jformSERQ_IMG').uploadify({
            'formData'     : {
    			'timestamp' : '<?php echo $timestamp;?>',
    			'token'     : '<?php echo md5('unique_salt' . $timestamp);?>',
                'SERQ_CODE' : '<?php echo HelperBG::getIDAuto('serq','SERQ_CODE'); ?>'
    		},
            'multi'    : false,
            'removeTimeout' : 1,
            'fileSizeLimit' : '26MB',
            'buttonText' : '画像を選択してください。',
            'width'    : 170,
            'swf'      : 'components/com_questionare/public/uploadlib/uploadify.swf',
            'uploader' : 'components/com_questionare/public/uploadlib/uploadify.php',           
            'onUploadSuccess' : function(file, data, response) {
                
                /* show image */
                $('#preview').html(
                '<img style="width: 100px; height: 100px;" id="showimg" src="uploads/images/com_questionare/'+data+'" />');
                $('#value_SERQ_IMG').val(data);
            }
            // Put your options here
        });
    });
    
    /* remove anh chon khi click cancel */
    Joomla.submitbutton = function(task){
        if(task == 'cancel'){
                var image_name_old = jq('#value_SERQ_IMG').val();
                if(image_name_old != ''){
                    jq.ajax({
                      url: 'index.php?option=com_questionare&task=removeImage'+'&image_name='+image_name_old,
                      context: document.body
                    }).done(function(data ) {
                        
                    });
                }
        }

        /*Confirm khi chon public bang hoi*/
        if(task == 'save' || task == 'savetemp'){
            var publish = document.getElementById("jform[SERQ_PUBLISHED]").value;
            if(publish == "1"){
                if(confirm('フロントページが「公開」になっています。「登録」または「一時保存」後、編集したい場合は、フロントページを「非公開」にしてください。このまま実行してもよろしいですか？')){
                    Joomla.submitform(task, document.getElementById('adminForm'));  
                }
                else{
                    return false; 
                }
            } 
            else{
                Joomla.submitform(task, document.getElementById('adminForm'));  
            }
        }

        Joomla.submitform(task, document.getElementById('adminForm'));
    }
        
        window.addEvent('domready', function() {Calendar.setup({
        	// Id of the input field
        	inputField: "jformSERQ_START",
        	// Format of the input field
        	ifFormat: "%Y/%m/%d",
        	// Trigger for the calendar (button ID)
        	button: "jformSERQ_START",
        	// Alignment (defaults to "Bl")
        	align: "Bl",
        	singleClick: true,
        	firstDay: 0
    	});
    
    });
    
     window.addEvent('domready', function() {Calendar.setup({
        	// Id of the input field
        	inputField: "jformSERQ_FINISH",
        	// Format of the input field
        	ifFormat: "%Y/%m/%d",
        	// Trigger for the calendar (button ID)
        	button: "jformSERQ_FINISH",
        	// Alignment (defaults to "Bl")
        	align: "Bl",
        	singleClick: true,
        	firstDay: 0
    	});
    
    });
</script>
<script>
    jq(document).ready(function() {

        // show a dialog box when clicking on a link
        jq('#btnSERQ_SEND_USER_ID_LIST').bind('click', function(e) {
            e.preventDefault();
            jq.Zebra_Dialog('', {
                source:  {'ajax': 'index.php?option=com_questionare&view=bg&task=popup&tmpl=component'},
                /*source: {'iframe': {
                    
                    'src':  'index.php?option=com_popup&view=bg&task=popup&tmpl=component',
                    'height': 450
                }},*/
                height: 750,
                width: 850,
                title:  '配信先選択',
                type:  '',
                buttons:  [
                    {caption: 'キャンセル', callback: function() {}},
                    {caption: 'OK', callback: function() {
                        jq('#jformMAIL_USER').val(jq('#jformMAIL_USER').val()+jq('#list_uid').val());
                    }
                        
                    }
                ]
            });
        });   
                        
     });
</script>

